<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('付款计划列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>计划名称：</label>
                                <input type="text" name="planName"/>
                            </li>
                            <li>
                                <label>成本中心：</label>
                                <select name="businessUnitDepartmentId" th:with="type=${@customDictService.selectDictBusinessUnitWithDepartments()}">
                                    <option value="">请选择</option>
                                    <optgroup th:each="unit: ${type}" th:label="${unit.name}">
                                        <option th:each="department : ${unit.departments}" th:text="${department.name}" th:value="${department.id}"></option>
                                    </optgroup>
                                </select>
                            </li>
<!--                            <li>-->
<!--                                <label>项目：</label>-->
<!--                                <select name="projectId"  th:width="type=${@customDictService.selectDictAllProject()}">-->
<!--                                    <option value="">&#45;&#45;请选择&#45;&#45;</option>-->
<!--                                    <option th:each="project : ${type}" th:text="${project.title}" th:value="${project.id}"></option>-->
<!--                                </select>-->
<!--                            </li>-->
                            <li>
                                <label>付款分类：</label>
                                <select name="payableType" th:with="type=${@dict.getType('payable_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>付款类目：</label>
                                <select name="payableCategory" th:with="type=${@dict.getType('payable_category')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>预计金额：</label>
                                <input type="text" name="expectAmount"/>
                            </li>
                            <li>
                                <label>预计时间：</label>
                                <input type="text" class="time-input" style="width: 100px;" placeholder="开始时间" name="params[beginTime]"/>
                                <span> - </span>
                                <input type="text" class="time-input" style="width: 100px;" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <label>付款状态：</label>
                                <select name="params[payStatus]">
                                    <option value="">--请选择--</option>
                                    <option value="0">未付清</option>
                                    <option value="1">已付清</option>
                                </select>
                            </li>
                            <li>
                                <label>审批状态：</label>
                                <select name="approveStatus" th:with="type=${@dict.getType('payable_approve_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>


                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>


            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:payable:plan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:payable:plan:remove')}]];
        var approveStatusDatas = [[${@dict.getType('payable_approve_status')}]];
        var statusDatas = [[${@dict.getType('delete_flag')}]];
        var planNumberDatas = [[${@dict.getType('account_number')}]];
        var payableTypeDatas = [[${@dict.getType('payable_type')}]];
        var payableCategoryDatas = [[${@dict.getType('payable_category')}]];
        var prefix = ctx + "erp/payable/plan";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: 'id',
                sortOrder: 'DESC',
                modalName: "付款计划",
                showColumns: false,
                showToggle: false,
                showSearch: false,
                showRefresh: false,
                onClickCell: onClickCell,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'planName',
                    title: '计划名称'
                },
                {
                    field: 'businessUnitDepartmentName',
                    title: '成本中心'
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'planNumber',
                    title: '第几笔付款',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(planNumberDatas, value);
                    }
                },
                {
                    field: 'receiver',
                    title: '收款人'
                },
                {
                    field: 'expectTime',
                    title: '预计付款时间'
                },
                {
                    field: 'expectAmount',
                    title: '预计付款金额'
                },
                {
                    field: 'payedAmount',
                    title: '已付金额',
                    cellStyle: function (value, row, index){
                        return {
                            css: {color: "blue",cursor: "pointer"}
                        }
                    }
                },
                {
                    field: 'latestPayTime',
                    title: '最后付款',
                    formatter(value, row)
                    {
                        return $.common.dateFormat(value, 'yyyy-MM-dd');
                    }
                },
                {
                    field: 'payedStatus',
                    title: '付款状态'
                },
                {
                    field: 'payableType',
                    title: '付款类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(payableTypeDatas, value);
                    }
                },
                {
                    field: 'payableCategory',
                    title: '付款类目',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(payableCategoryDatas, value);
                    }
                },
                {
                    field: 'approveStatus',
                    title: '审批状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(approveStatusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        var addDetailUrl = "/erp/payable/payable/add/" + row.id;
                        var addDetailTitle = row.planName + " 新增付款"
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.modal.open(\'' + addDetailTitle + '\',\'' + addDetailUrl + '\')"><i class="fa fa-dollar"></i>付款</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function onClickCell(field, value, row, $element){
            if (field == 'payedAmount' && value != 0){
                var tittle = row.planName  + '收款记录' ;
                var detailUrl = "/erp/payable/payable/" + row.id;
                $.modal.openTab(tittle,detailUrl);
            }
        }
    </script>
</body>
</html>